<?php

namespace App\Api\Controllers;

use App\Api\Foundation\Controllers\Controller;
use App\Models\Area;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class publicController extends Controller
{
    /*
    *城市地区列表
    */
	public function cityList(Request $request)
    {
        $citylist =  Area::where('level', 1)->where('visible', 2)->select('id', 'name')->get()->toArray();
        foreach ($citylist as $key => &$prov) {
            $prov['area'] = Area::where('level', 2)->where('pid', $prov['id'])->where('visible', 2)->select('id', 'name')->get()->toArray();
            foreach ($prov['area'] as $k => &$area) {
                $area['dist'] = Area::where('level', 3)->where('pid', $area['id'])->where('visible', 2)->select('id', 'name')->get()->toArray();
            }
        }

    	return $this->succeed($citylist);
    }

    /*
    *获取七牛云token
    */
    public function qiniuToken()
    {
        $accesskey = 'PwenrBRyDlRaK7Uwo4pFfJEhKUYvsU-CpbuTaEy8';
        $secretkey = 'IB-cd1g-NV5NULh5h0JW96CYDPkwS5BYDje0l8XM';
        $bucket = 'cmmczhcs';
        $url = 'http://img.fb.cn';
        $auth = new \Qiniu\Auth($accesskey, $secretkey);
        $token = $auth->uploadToken($bucket);

        return $this->succeed($token);

    }

}